package br.ufpe.cin.msc.jrsj2.recommender;

import br.ufpe.cin.msc.jrsj2.recommender.persistence.dao.ChannelDAO;
import br.ufpe.cin.msc.jrsj2.recommender.persistence.dao.ClientDAO;
import br.ufpe.cin.msc.jrsj2.recommender.persistence.dao.DAOFactory;
import br.ufpe.cin.msc.jrsj2.recommender.persistence.domain.Channel;
import br.ufpe.cin.msc.jrsj2.recommender.persistence.domain.Client;
import br.ufpe.cin.msc.jrsj2.recommender.util.ClientHash;

public class Bootstrap {

	private static void setUpChannels() {
		ChannelDAO channelDAO = DAOFactory.getDAOFactory().getChannelDAO();

		/*
		 * if (channelDAO.findByName("BBC") == null) { channelDAO.create(new
		 * Channel("BBC", "http://www.bbc.co.uk/programmes")); }
		 */

		if (channelDAO.findByName("discovery") == null) {
			channelDAO.create(new Channel("discovery",
					"http://127.0.0.1/metadata/discovery"));
		}

		if (channelDAO.findByName("fox") == null) {
			channelDAO.create(new Channel("fox",
					"http://127.0.0.1/metadata/fox"));
		}

		if (channelDAO.findByName("foxlife") == null) {
			channelDAO.create(new Channel("foxlife",
					"http://127.0.0.1/metadata/foxlife"));
		}

		if (channelDAO.findByName("homeandhealth") == null) {
			channelDAO.create(new Channel("homeandhealth",
					"http://127.0.0.1/metadata/homeandhealth"));
		}

		if (channelDAO.findByName("Globo") == null) {
			channelDAO.create(new Channel("Globo",
					"http://127.0.0.1/metadata/Globo"));
		}

		if (channelDAO.findByName("TV Tribuna") == null) {
			channelDAO.create(new Channel("TV Tribuna",
					"http://127.0.0.1/metadata/TV%20Tribuna"));
		}

		if (channelDAO.findByName("RedeTV!") == null) {
			channelDAO.create(new Channel("RedeTV!",
					"http://127.0.0.1/metadata/RedeTV!"));
		}

		/*
		 * if (channelDAO.findByName("tvcultura") == null) {
		 * channelDAO.create(new Channel("tvcultura",
		 * "http://127.0.0.1/metadata/tvcultura")); }
		 */

		if (channelDAO.findByName("TV Clube") == null) {
			channelDAO.create(new Channel("TV Clube",
					"http://127.0.0.1/metadata/TV%20Clube"));
		}

		if (channelDAO.findByName("MTV") == null) {
			channelDAO.create(new Channel("MTV",
					"http://127.0.0.1/metadata/MTV"));
		}
	}

	private static void setUpPrograms() {
		return;
	}

	private static void setUpClients() {
		ClientDAO clientDAO = DAOFactory.getDAOFactory().getClientDAO();

		for (int i = 1; i <= 9; i++) {
			String hash = ClientHash.getClientHashString("Client " + i);
			if (clientDAO.findByHash(hash) == null)
				clientDAO.create(new Client(hash));
		}

		/*
		 * if (clientDAO.findByHash("Active Client") == null)
		 * clientDAO.create(new Client("Active Client"));
		 */
	}

	public static void exec() {
		setUpChannels();
		setUpPrograms();
		setUpClients();
	}

}
